package Test_1108;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class CardFunctions {
    //洗牌
    public void washCard(List<Card> cardList){
        Random random=new Random();
        for (int i = cardList.size()-1; i >0 ; i--) {
            //生成范围在0到51之间，随着交换次数，范围不断减少
            int index=random.nextInt(i);
            //交换牌
            swap(i,index,cardList);
        }
    }
    private void swap(int i,int j,List<Card> cardList){
         /* Card tmp=cardList[i];
          cardList[i]=cardList[j];
          cardList[j]=tmp;*/
        Card tmp=cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }
    //发牌
    public List<List<Card>> dealCard(List<Card> cardList){
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();
        List<Card> hand3=new ArrayList<>();
        List<List<Card>> hand=new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card=cardList.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}
